package org.misalen.web.admin.controllers;

import java.util.Date;

import org.misalen.web.admin.util.ServerResult;
import org.misalen.web.database.model.mysql.pro.ProUserBanner;
import org.misalen.web.database.util.PaginationFrom;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "/pro-user-banner")
public class ProUserBannerController extends BaseController {

	/**
	 * 列表页
	 * 
	 * @return 列表目标页
	 */
	@RequestMapping(value = "/", method = { RequestMethod.GET })
	public ModelAndView list() {
		ModelAndView modelAndView = new ModelAndView("/proUserBanner/list");
		return modelAndView;
	}

	/**
	 * 列表
	 * 
	 * @param 搜索条件
	 * @param 分页/排序条件
	 * @return 查询结果
	 */
	@RequestMapping(value = "/", method = { RequestMethod.POST })
	public @ResponseBody ServerResult listPost(ProUserBanner proUserBanner, PaginationFrom<ProUserBanner> pagination) {
		PaginationFrom<ProUserBanner> from = proUserBannerRepository.findPageByBean(proUserBanner, pagination);
		return renderSuccess(from);
	}

	/**
	 * 详情
	 * 
	 * @param 主键
	 * @return 单条详情目标页
	 */
	@RequestMapping(value = "/{primaryKey}", method = { RequestMethod.GET })
	public ModelAndView details(@PathVariable String primaryKey) {
		ModelAndView modelAndView = new ModelAndView("/proUserBanner/details");
		modelAndView.addObject("info", proUserBannerRepository.get(ProUserBanner.class, primaryKey));
		return modelAndView;
	}

	/**
	 * 添加页面
	 * 
	 * @return 添加目标页
	 */
	@RequestMapping(value = "/add", method = { RequestMethod.GET })
	public ModelAndView add() {
		ModelAndView modelAndView = new ModelAndView("/proUserBanner/add");
		return modelAndView;
	}

	/**
	 * 添加动作
	 * 
	 * @param 信息
	 * @return 添加后的信息
	 */
	@RequestMapping(value = "/add", method = { RequestMethod.POST })
	public @ResponseBody ServerResult addPost(ProUserBanner proUserBanner) {
		proUserBanner.setAddTime(new Date());
		proUserBannerRepository.save(proUserBanner);
		return renderSuccess(proUserBanner);
	}

	/**
	 * 更新页面
	 * 
	 * @param 主键
	 * @return 更新目标页
	 */
	@RequestMapping(value = "/{primaryKey}/update", method = { RequestMethod.GET })
	public ModelAndView update(@PathVariable String primaryKey) {
		ProUserBanner proUserBanner = proUserBannerRepository.get(ProUserBanner.class, primaryKey);
		ModelAndView modelAndView = new ModelAndView("/proUserBanner/update");
		modelAndView.addObject("info", proUserBanner);
		return modelAndView;
	}

	/**
	 * 更新动作
	 * 
	 * @param 信息
	 * @return 更新后的信息
	 */
	@RequestMapping(value = "/update", method = { RequestMethod.POST })
	public @ResponseBody ServerResult updatePost(ProUserBanner proUserBanner) {
		proUserBannerRepository.update(proUserBanner);
		return renderSuccess(proUserBanner);
	}

	/**
	 * 删除
	 * 
	 * @param 主键
	 * @return 删除结果
	 */
	@RequestMapping(value = "/{primaryKey}/del", method = { RequestMethod.GET })
	public @ResponseBody Boolean del(@PathVariable String primaryKey) {
		proUserBannerRepository.delete(ProUserBanner.class, primaryKey);
		return true;
	}
}
